package com.superteam.zzl.Des;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.superteam.zzl.activity.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class CountryActivity extends AppCompatActivity implements GridView.OnItemClickListener{
    private View headview;
    private ListView lv,headlv;
    private MyGridAdapter adapter;
   private String shuju1;
    private List<Country.DataBean.CityListBean> citylist;
    private List<Country.DataBean.CountryInfoBean> countrylist;
    private HeadviewAdapter adapter1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.co);
        Intent intent=getIntent();
        shuju1=intent.getStringExtra("shuju1");
        init();
    }

    private void init() {
        headview=View.inflate(this,R.layout.headview,null);
        lv=(ListView)findViewById(R.id.isalv);

        citylist=new ArrayList<>();
        countrylist=new ArrayList<>();

        headlv=(ListView)headview.findViewById(R.id.headlv);

        adapter=new MyGridAdapter(this,citylist);
        adapter1=new HeadviewAdapter(this,countrylist);
        headlv.setAdapter(adapter1);
        lv.addHeaderView(headview);
        lv.setAdapter(adapter);

    loadData();
    }

    private void loadData() {
        new JsonAsyncTask(this, new JsonAsyncTask.CallBack() {
            @Override
            public void sendData(String json) {
               Country country=new Gson().fromJson(json,Country.class);
                citylist.addAll(country.data.city_list);
                countrylist.add(country.data.country_info);
                adapter.notifyDataSetChanged();
                adapter1.notifyDataSetChanged();
            }
        }).execute(shuju1);
    }

    public void click(View view) {
        finish();
      //  Toast.makeText(this,"sa",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


    }
}
